package com.brand.controller;

import com.brand.service.BrandService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/deleteByIdServlet")
public class DeleteByIdServlet extends HttpServlet {
    private BrandService service = new BrandService();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("deleteByIdServlet_doGet?");
        //接收参数id
        String id = req.getParameter("id");
        //调用BrandService完成删除
        service.deleteById(Integer.parseInt(id));
        //转发到查询所有Servlet
        req.getRequestDispatcher("/selectAllServlet").forward(req, resp);

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("deleteByIdServlet_doPost?");
        this.doGet(req, resp);
    }
}
